package myjava;

import java.awt.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
    //    cat c1=new cat("java",11,21,"white");
    //    System.out.println(c1);


        cangying c=new cangying(6);
        c.fly();
        c.repoduce();
    }
}

/*猫类习题：显示输出
name:java
age:11
weight:21.0
color:java.awt.Color[r=255,g=255,b=255]
 */
class  cat{ //p131 猫类习题，难点：重写toString()换行；color 从string转到Color可用
    String name; //定义猫名字
    int age;
    float weight;
    String color;
    Color mycolor;


    public cat(String name, int age,float weight,String color)  {
        this.name =name;
        this.age =age;
        this.weight=weight;
        this.color=color;


    }
    public String toString(){
        return "name:"+name+"\r\n"+"age:"+age+"\r\n"+"weight:"+weight+"\r\n"+"color:"+mycolor(color);
    }
    public  Color mycolor(String color){ //color 从string 转为color（）

        switch (color){
            case "red":
                mycolor=Color.RED;
                break;
            case "white":
                mycolor=Color.WHITE;
                break;
        }
        return mycolor;

    }


}

/*苍蝇习题：显示输出
苍蝇有6腿
cangying can fly
cangying 繁殖
 */
interface  Flyable{
    public void fly();
}
abstract class Insert{
    int legs;
    public void Insert(int legs){
        this.legs=legs;
    }
    abstract void repoduce();
}
class cangying extends Insert implements Flyable{
    public cangying(int legs){
        System.out.println("苍蝇有"+legs+"腿");
    }
    public void fly(){
        System.out.println("cangying can fly");
    }
    public void repoduce(){
        System.out.println("cangying 繁殖");
    }
}
